package com.example.denlu;

import java.util.HashMap;
import java.util.Map;
 
import org.json.JSONObject;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
 
 
public class MainActivity extends Activity {
    private EditText edname;  
    private EditText edpassword;   
    private Button btregister;  
    private Button btlogin;  
    private String name;
    private String password;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        edname = (EditText) findViewById(R.id.edname);  
        edpassword = (EditText) findViewById(R.id.edpassword);  
        btregister = (Button) findViewById(R.id.btregister);  
        btlogin = (Button) findViewById(R.id.btlogin);  
        // 跳转到注册界面  
        btregister.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
                Intent intent = new Intent();  
                intent.setClass(MainActivity.this, RegistersActivity.class);  
                startActivity(intent);  
            }  
        });  
        btlogin.setOnClickListener(new LoginListener());  

    }
    class LoginListener implements OnClickListener {  
    	  
        @Override  
        public void onClick(View v) {  
            // TODO Auto-generated method stub  
             name = edname.getText().toString();  
             password = edpassword.getText().toString();  
            if (name.equals("") || password.equals("")) {  
                // 弹出消息框  
                new AlertDialog.Builder(MainActivity.this).setTitle("错误")  
                        .setMessage("帐号或密码不能空").setPositiveButton("确定", null)  
                        .show();  
            } else {  
                isUserinfo(name, password);  
            }  
        }  
    }
 // 判断输入的用户是否正确  
    public Boolean isUserinfo(String name2, String pwd) {  
        try{  
            if(name.equals("abc") && password.equals("123")){  
                new AlertDialog.Builder(MainActivity.this).setTitle("正确")  
                .setMessage("成功登录").setPositiveButton("确定", null)  
                .show(); 
                return true;  
            }else{  
                new AlertDialog.Builder(MainActivity.this).setTitle("错误")  
                .setMessage("帐号或密码错误！").setPositiveButton("确定", null)  
                .show();  
                return false;  
            }  
              
        }catch(Exception e){  
              
        }  
        return false;  
    }  
  
}